local skel = fk.CreateSkill {
  name = "lb__baihe",
}

Fk:loadTranslationTable {
  ["lb__baihe"] = "捭阖",
  [":lb__baihe"] = "出牌阶段限一次，若你的判定区同时有“辣”和“清”，你可重铸其中一种花色最多的牌并视为使用剩余牌中的一张基本牌或普通锦囊牌。",

  ["#lb__baihe"] = "捭阖：你可以重铸判定区一种花色的所有牌",

  ["$lb__baihe1"] = "三思而行，再思可矣。",
  ["$lb__baihe2"] = "与其伺机而动，不如一动不动。",
}

skel:addEffect("active", {
  anim_type = "drawcard",
  prompt = "#lb__baihe",
  can_use = function(self, player)
    return player:usedSkillTimes("lb__baihe", Player.HistoryPhase) == 0
        and table.find(player:getCardIds("j"), function(id) return Fk:getCardById(id).color == Card.Red end)
        and table.find(player:getCardIds("j"), function(id) return Fk:getCardById(id).color == Card.Black end)
  end,
  card_filter = Util.FalseFunc,
  target_filter = Util.FalseFunc,
  interaction = function(self, player)
    local s = {}
    local n = 0
    local ask = {}
    for i, suit in ipairs({ Card.Heart, Card.Spade, Card.Club, Card.Diamond }) do
      table.insert(s, table.filter(player:getCardIds("j"), function(id) return Fk:getCardById(id).suit == suit end))
      n = math.max(n, #s[i])
    end
    for _, suit in ipairs(s) do
      if #suit == n then
        table.insert(ask, Fk:getCardById(suit[1]):getSuitString())
      end
    end
    return UI.ComboBox {
      choices = ask,
    }
  end,
  on_use = function(self, room, effect)
    local player = effect.from
    local recast, use = {}, {}
    for _, id in ipairs(player:getCardIds("j")) do
      local card = Fk:getCardById(id)
      if card:getSuitString() == self.interaction.data then
        table.insert(recast, id)
      elseif card.type == Card.TypeBasic or card:isCommonTrick() then
        table.insertIfNeed(use, card.name)
      end
    end
    room:recastCard(recast, player, "lb__baihe")
    room:askToUseVirtualCard(player, {
      name = use,
      skill_name = skel.name,
      cancelable = false,
    })
  end,
})

return skel
